package cn.nju.sirx.algorithm.sort;

/**
 * Bubble sort.
 * 
 * @author SirX
 */
public class BubbleSort implements ISort {

    @Override
    public <T extends Comparable<? super T>> void sort(T[] data) {
        for (int i = data.length - 1; i > 0; i--) {
            for (int j = 0; j < i; j++) {
                if (data[j].compareTo(data[j + 1]) > 0) {
                    T tmp = data[j];
                    data[j] = data[j + 1];
                    data[j + 1] = tmp;
                }
            }
        }
    }

}
